package com.sgb.kjwl.view.ui.activity.self.carMaster;

import android.content.Context;
import android.content.Intent;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMyOfferBinding;
import com.sgb.kjwl.view.ui.adapter.transport.CargoManageHomeTabAdapter;
import com.sgb.kjwl.view.ui.fragment.self.TruckApplyFragment;
import com.sgb.kjwl.view.ui.fragment.transport.BiddingMyOfferFragment;
import com.sgb.kjwl.view.ui.fragment.transport.NormalMyOfferFragment;
import com.sgb.kjwl.viewmodel.self.carMakers.MyOfferModel;

import com.swgk.core.common.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import me.yokeyword.fragmentation.ISupportFragment;

/**
 * @author: 杨畔
 * @date: 2021/2/6 16:27
 * @Description: 我的报价页面
 */
public class MyOfferActivity extends BaseActivity<MyOfferModel, ActivityMyOfferBinding> {
    //顶部tab
    private CargoManageHomeTabAdapter mTabAdapter;
    //子页面
    private final ISupportFragment[] mFragments = new ISupportFragment[2];

    @Override
    protected int layoutId() {
        return R.layout.activity_my_offer;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(MyOfferModel.class);
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, MyOfferActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected void init() {
        mBinding.include.titleView.setText("车主报价");
        mBinding.include.ivBack.setOnClickListener(v -> finish());
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction beginTransaction = manager.beginTransaction();
        beginTransaction.add(R.id.fragment_my_offer_and_order, NormalMyOfferFragment.newInstance());
        beginTransaction.commit();

//        initPage();
//        initTab();
//        mBinding.ivBack.setOnClickListener(view -> finish());
    }

    private void initPage() {
        mFragments[0] = NormalMyOfferFragment.newInstance();
        mFragments[1] = BiddingMyOfferFragment.newInstance();
        loadMultipleRootFragment(R.id.fragment_my_offer_and_order, 0,
                mFragments[0],
                mFragments[1]);
    }

    private void initTab() {
        List<String> tabs = new ArrayList<>();
        tabs.add("普通货源");
        tabs.add("竞价货源");
        mTabAdapter = new CargoManageHomeTabAdapter(tabs);
        mBinding.rvTab.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
        mBinding.rvTab.setAdapter(mTabAdapter);
        mTabAdapter.setOnItemClickListener((adapter, view, position) -> {
            mTabAdapter.setSelectIndex(position);
            switch (position) {
                case 0:
                    showHideFragment(mFragments[0]);
                    break;
                case 1:
                    showHideFragment(mFragments[1]);
                    break;
            }
        });
    }
}

